namespace DotNetNuke.UI.UserControls
{
    using DotNetNuke.Common;
    using DotNetNuke.Common.Utilities;
    using DotNetNuke.Entities.Tabs;
    using DotNetNuke.Framework;
    using DotNetNuke.Services.Exceptions;
    using DotNetNuke.Services.FileSystem;
    using DotNetNuke.Services.Localization;
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Web.UI.WebControls;

    public class URLTrackingControl : UserControlBase
    {
        private static List<WeakReference> __ENCList = new List<WeakReference>();
        //("cmdDisplay")]
        private LinkButton _cmdDisplay;
        //("cmdEndCalendar")]
        private HyperLink _cmdEndCalendar;
        //("cmdStartCalendar")]
        private HyperLink _cmdStartCalendar;
        private string _FormattedURL;
        //("grdLog")]
        private DataGrid _grdLog;
        //("lblClicks")]
        private Label _lblClicks;
        //("lblCreatedDate")]
        private Label _lblCreatedDate;
        //("lblLastClick")]
        private Label _lblLastClick;
        //("lblLogURL")]
        private Label _lblLogURL;
        //("lblTrackingURL")]
        private Label _lblTrackingURL;
        //("lblURL")]
        private Label _lblURL;
        private string _localResourceFile;
        private int _ModuleID;
        //("pnlLog")]
        private Panel _pnlLog;
        //("pnlTrack")]
        private Panel _pnlTrack;
        private string _TrackingURL;
        //("txtEndDate")]
        private TextBox _txtEndDate;
        //("txtStartDate")]
        private TextBox _txtStartDate;
        private string _URL;
        //("valEndDate")]
        private CompareValidator _valEndDate;
        //("valStartDate")]
        private CompareValidator _valStartDate;
        protected Label Label1;
        protected Label Label2;
        protected Label Label3;
        protected Label Label4;
        protected Label Label5;
        protected Label Label6;
        protected Label Label7;

        public URLTrackingControl()
        {
            base.Init += new EventHandler(this.Page_Init);
            base.Load += new EventHandler(this.Page_Load);
            List<WeakReference> refObjectHelperL0 = __ENCList;
            lock (refObjectHelperL0)
            {
                __ENCList.Add(new WeakReference(this));
            }
            this._URL = "";
            this._FormattedURL = "";
            this._TrackingURL = "";
            this._ModuleID = -2;
        }

        private void cmdDisplay_Click(object sender, EventArgs e)
        {
            try
            {
                string strStartDate = this.txtStartDate.Text;
                if (strStartDate != "")
                {
                    strStartDate = strStartDate + " 00:00";
                }
                string strEndDate = this.txtEndDate.Text;
                if (strEndDate != "")
                {
                    strEndDate = strEndDate + " 23:59";
                }
                UrlController objUrls = new UrlController();
                DataGrid refObjectHelperS0 = this.grdLog;
                DotNetNuke.Services.Localization.Localization.LocalizeDataGrid(ref refObjectHelperS0, this.LocalResourceFile);
                this.grdLog = refObjectHelperS0;
                this.grdLog.DataSource = objUrls.GetUrlLog(this.PortalSettings.PortalId, this.lblLogURL.Text, this.ModuleID, Convert.ToDateTime(strStartDate), Convert.ToDateTime(strEndDate));
                this.grdLog.DataBind();
            }
            catch (Exception exception1)
            {
                
                Exception exc = exception1;
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
                
            }
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
        }

        private void Page_Init(object sender, EventArgs e)
        {
            this.InitializeComponent();
        }

        private void Page_Load(object sender, EventArgs e)
        {
            try
            {
                this.cmdStartCalendar.NavigateUrl = DotNetNuke.Common.Utilities.Calendar.InvokePopupCal(this.txtStartDate);
                this.cmdEndCalendar.NavigateUrl = DotNetNuke.Common.Utilities.Calendar.InvokePopupCal(this.txtEndDate);
                if (!this.Page.IsPostBack)
                {
                    if (this._URL != "")
                    {
                        this.lblLogURL.Text = this.URL;
                        if (DotNetNuke.Common.Globals.GetURLType(this._URL) == TabType.File)
                        {
                            FileController objFiles = new FileController();
                            this.lblLogURL.Text = "FileID=" + objFiles.ConvertFilePathToFileId(this._URL, this.PortalSettings.PortalId).ToString();
                        }
                        UrlTrackingInfo objUrlTracking = new UrlController().GetUrlTracking(this.PortalSettings.PortalId, this.lblLogURL.Text, this.ModuleID);
                        if (objUrlTracking != null)
                        {
                            Label refObjectHelperS0;
                            if (this._FormattedURL == "")
                            {
                                if (!this.URL.StartsWith("http") & !this.URL.StartsWith("mailto"))
                                {
                                    this.lblURL.Text = DotNetNuke.Common.Globals.AddHTTP(this.Request.Url.Host);
                                }
                                refObjectHelperS0 = this.lblURL;
                                refObjectHelperS0.Text = refObjectHelperS0.Text + DotNetNuke.Common.Globals.LinkClickURL(this.URL);
                            }
                            else
                            {
                                this.lblURL.Text = this._FormattedURL;
                            }
                            this.lblCreatedDate.Text = objUrlTracking.CreatedDate.ToString();
                            if (objUrlTracking.TrackClicks)
                            {
                                this.pnlTrack.Visible = true;
                                if (this._TrackingURL == "")
                                {
                                    if (!this.URL.StartsWith("http"))
                                    {
                                        this.lblTrackingURL.Text = DotNetNuke.Common.Globals.AddHTTP(this.Request.Url.Host);
                                    }
                                    refObjectHelperS0 = this.lblTrackingURL;
                                    refObjectHelperS0.Text = refObjectHelperS0.Text + DotNetNuke.Common.Globals.LinkClick(this.URL, this.PortalSettings.ActiveTab.TabID, this.ModuleID, objUrlTracking.TrackClicks);
                                }
                                else
                                {
                                    this.lblTrackingURL.Text = this._TrackingURL;
                                }
                                this.lblClicks.Text = objUrlTracking.Clicks.ToString();
                                if (!Null.IsNull(objUrlTracking.LastClick))
                                {
                                    this.lblLastClick.Text = objUrlTracking.LastClick.ToString();
                                }
                            }
                            if (objUrlTracking.LogActivity)
                            {
                                this.pnlLog.Visible = true;
                                this.txtStartDate.Text = DateAndTime.DateAdd(DateInterval.Day, -6.0, DateTime.Today).ToShortDateString();
                                this.txtEndDate.Text = DateAndTime.DateAdd(DateInterval.Day, 1.0, DateTime.Today).ToShortDateString();
                            }
                        }
                    }
                    else
                    {
                        this.Visible = false;
                    }
                }
            }
            catch (Exception exception1)
            {
                
                Exception exc = exception1;
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
                
            }
        }

        protected virtual LinkButton cmdDisplay
        {
           
            get
            {
                return this._cmdDisplay;
            }
            
            set
            {
                EventHandler handler = new EventHandler(this.cmdDisplay_Click);
                if (this._cmdDisplay != null)
                {
                    this._cmdDisplay.Click -= handler;
                }
                this._cmdDisplay = value;
                if (this._cmdDisplay != null)
                {
                    this._cmdDisplay.Click += handler;
                }
            }
        }

        protected virtual HyperLink cmdEndCalendar
        {
           
            get
            {
                return this._cmdEndCalendar;
            }
            
            set
            {
                this._cmdEndCalendar = value;
            }
        }

        protected virtual HyperLink cmdStartCalendar
        {
           
            get
            {
                return this._cmdStartCalendar;
            }
            
            set
            {
                this._cmdStartCalendar = value;
            }
        }

        public string FormattedURL
        {
            get
            {
                return this._FormattedURL;
            }
            set
            {
                this._FormattedURL = value;
            }
        }

        protected virtual DataGrid grdLog
        {
           
            get
            {
                return this._grdLog;
            }
            
            set
            {
                this._grdLog = value;
            }
        }

        protected virtual Label lblClicks
        {
           
            get
            {
                return this._lblClicks;
            }
            
            set
            {
                this._lblClicks = value;
            }
        }

        protected virtual Label lblCreatedDate
        {
           
            get
            {
                return this._lblCreatedDate;
            }
            
            set
            {
                this._lblCreatedDate = value;
            }
        }

        protected virtual Label lblLastClick
        {
           
            get
            {
                return this._lblLastClick;
            }
            
            set
            {
                this._lblLastClick = value;
            }
        }

        protected virtual Label lblLogURL
        {
           
            get
            {
                return this._lblLogURL;
            }
            
            set
            {
                this._lblLogURL = value;
            }
        }

        protected virtual Label lblTrackingURL
        {
           
            get
            {
                return this._lblTrackingURL;
            }
            
            set
            {
                this._lblTrackingURL = value;
            }
        }

        protected virtual Label lblURL
        {
           
            get
            {
                return this._lblURL;
            }
            
            set
            {
                this._lblURL = value;
            }
        }

        public string LocalResourceFile
        {
            get
            {
                if (this._localResourceFile == "")
                {
                    return (this.TemplateSourceDirectory + "/App_LocalResources/URLTrackingControl.ascx");
                }
                return this._localResourceFile;
            }
            set
            {
                this._localResourceFile = value;
            }
        }

        public int ModuleID
        {
            get
            {
                int ModuleID = this._ModuleID;
                if ((ModuleID == -2) && (this.Request.QueryString["mid"] != null))
                {
                    ModuleID = int.Parse(this.Request.QueryString["mid"]);
                }
                return ModuleID;
            }
            set
            {
                this._ModuleID = value;
            }
        }

        protected virtual Panel pnlLog
        {
           
            get
            {
                return this._pnlLog;
            }
            
            set
            {
                this._pnlLog = value;
            }
        }

        protected virtual Panel pnlTrack
        {
           
            get
            {
                return this._pnlTrack;
            }
            
            set
            {
                this._pnlTrack = value;
            }
        }

        public string TrackingURL
        {
            get
            {
                return this._TrackingURL;
            }
            set
            {
                this._TrackingURL = value;
            }
        }

        protected virtual TextBox txtEndDate
        {
           
            get
            {
                return this._txtEndDate;
            }
            
            set
            {
                this._txtEndDate = value;
            }
        }

        protected virtual TextBox txtStartDate
        {
           
            get
            {
                return this._txtStartDate;
            }
            
            set
            {
                this._txtStartDate = value;
            }
        }

        public string URL
        {
            get
            {
                return this._URL;
            }
            set
            {
                this._URL = value;
            }
        }

        protected virtual CompareValidator valEndDate
        {
           
            get
            {
                return this._valEndDate;
            }
            
            set
            {
                this._valEndDate = value;
            }
        }

        protected virtual CompareValidator valStartDate
        {
           
            get
            {
                return this._valStartDate;
            }
            
            set
            {
                this._valStartDate = value;
            }
        }
    }
}

